package cn.seocoo.platform.contrast.service.impl;

import java.util.List;

import cn.seocoo.platform.car.dto.CarDto;
import cn.seocoo.platform.common.constant.ClassContants;
import cn.seocoo.platform.contrast.domain.CarContrast;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.seocoo.platform.contrast.mapper.ComparisonMapper;
import cn.seocoo.platform.contrast.domain.Comparison;
import cn.seocoo.platform.contrast.service.IComparisonService;
import cn.seocoo.platform.common.core.text.Convert;

/**
 * 车辆对比 服务层实现
 * 
 * @author wujian
 * @date 2020-01-02
 */
@Service
public class ComparisonServiceImpl implements IComparisonService 
{
	@Autowired
	private ComparisonMapper comparisonMapper;

	/**
     * 查询车辆对比信息
     * 
     * @param id 车辆对比ID
     * @return 车辆对比信息
     */
    @Override
	public Comparison selectComparisonById(Integer id)
	{
	    return comparisonMapper.selectComparisonById(id);
	}
	
	/**
     * 查询车辆对比列表
     * 
     * @param comparison 车辆对比信息
     * @return 车辆对比集合
     */
	@Override
	public List<Comparison> selectComparisonList(Comparison comparison)
	{
	    return comparisonMapper.selectComparisonList(comparison);
	}
	
    /**
     * 新增车辆对比
     * 
     * @param comparison 车辆对比信息
     * @return 结果
     */
	@Override
	public int insertComparison(Comparison comparison)
	{
	    return comparisonMapper.insertComparison(comparison);
	}
	
	/**
     * 修改车辆对比
     * 
     * @param comparison 车辆对比信息
     * @return 结果
     */
	@Override
	public int updateComparison(Comparison comparison)
	{
	    return comparisonMapper.updateComparison(comparison);
	}

	/**
     * 删除车辆对比对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteComparisonByIds(String ids)
	{
		return comparisonMapper.deleteComparisonByIds(Convert.toStrArray(ids));
	}

	/**
	 * @Author WuJian
	 * @Description //查询当前车辆是否在对比中
	 * @Date 22:41 2020/1/2
	 * @Param [appUserId, carId]
	 * @return java.util.List<cn.seocoo.platform.contrast.domain.Comparison>
	 **/
	@Override
	public List<Comparison> selectComparisonByUserAndCarId(Integer appUserId, Integer carId) {
		return comparisonMapper.selectComparisonByUserAndCarId(appUserId,carId);
	}

	@Override
	public int save(Integer appUserId, Integer carId) {
		Comparison comparison = new Comparison();
		comparison.setDelFlag(ClassContants.NO_DEL_FLAG);
		comparison.setAppUserId(appUserId);
		comparison.setCarInfoId(carId);
		return comparisonMapper.insertComparison(comparison);
	}

	/**
	 * @Author WuJian
	 * @Description //获取收藏列表
	 * @Date 23:06 2020/1/2
	 * @Param [pageNum, pageSize, appUserId]
	 * @return java.util.List<cn.seocoo.platform.car.dto.CarDto>
	 **/
	@Override
	public List<CarDto> getCarList(Integer pageNum, Integer pageSize, Integer appUserId) {
		PageHelper.startPage(pageNum == null? 1:pageNum,pageSize == null?10:pageSize);
		return comparisonMapper.getCarList(appUserId);
	}



	/**
	 * @Author WuJian
	 * @Description //清空
	 * @Date 19:03 2020/1/2
	 * @Param [id]
	 * @return int
	 **/
	@Override
	public int clearComparison(Integer id) {
		Comparison comparison = comparisonMapper.selectComparisonById(id);
		comparison.setDelFlag(ClassContants.IS_DEL_FLAG);
		return comparisonMapper.updateComparison(comparison);
	}


}
